#ifndef DOWNLOAD_H
#define DOWNLOAD_H

#include <QtCore>
#include <QDialog>
#include <QUrl>
#include <QMessageBox>
#include <QBuffer>
#include <QLabel>
#include <QProgressDialog>
#include <QHttp>
#include <QFileInfo>
#include <QCloseEvent>

class Download : public QDialog
{
Q_OBJECT

public:

Download( QUrl url, QString s, QString p = QString() );
~Download();
QUrl url;
QString purpose;
QString path;
QByteArray ba;
bool stopped;
QByteArray return_data();

public slots:

void request_finished( int, bool );
void cancel_download();
void update_progress( int read_bytes, int total_bytes );
void read_response_header(const QHttpResponseHeader & response_header);

signals:

void download_finished( Download * d,
                        bool ok,
                        QString s,
                        QString p,
			QString e );

private:

bool url_is_valid;
QProgressDialog * progressDialog;
QLabel * statusLabel;

protected:

QHttp * http;
int http_request_id;
QBuffer * buffer;
void closeEvent( QCloseEvent * e );

};

#endif // DOWNLOAD_H
